package com.ngc.mall.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ngc.mall.common.configure.mybatisPlus.BaseServiceImpl;
import com.ngc.mall.domain.IntegralSpuDomain;
import com.ngc.mall.mapper.IntegralSpuMapper;
import com.ngc.mall.service.IIntegralSpuService;
import com.ngc.mall.vo.PagingVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * 积分商品实现类
 * @author: chenxiaolin
 * @date 2023/9/13 16:17
**/
@Service
public class IntegralSpuServiceImpl extends BaseServiceImpl<IntegralSpuMapper, IntegralSpuDomain> implements IIntegralSpuService {

    @Override
    public Long createIntegralSpu(IntegralSpuDomain integralSpuDomain) {
        return super.create(integralSpuDomain);
    }

    @Override
    public List<IntegralSpuDomain> selectAll() {
        return super.list(Wrappers.<IntegralSpuDomain>lambdaQuery().orderByAsc(IntegralSpuDomain::getSort));
    }
    @Override
    public PagingVO<IntegralSpuDomain> selectAllShow(int start,int count){
//        return super.list(Wrappers.<IntegralSpuDomain>lambdaQuery().eq(IntegralSpuDomain::getIsEnabled,true).orderByAsc(IntegralSpuDomain::getSort));
        Page<IntegralSpuDomain> page=new Page<>(start,count);
        IPage iPage= super.page(page,Wrappers.<IntegralSpuDomain>lambdaQuery().eq(IntegralSpuDomain::getIsEnabled,true).orderByAsc(IntegralSpuDomain::getSort));
        PagingVO<IntegralSpuDomain> pagingVO=new PagingVO<>(iPage);
        return pagingVO;
    }

    @Override
    public Boolean exchange(Long id, Long uid) {
        return null;
    }


    @Override
    public Boolean updateStatusById(Long id, boolean status) {
        return super.update(Wrappers.<IntegralSpuDomain>lambdaUpdate().eq(IntegralSpuDomain::getId,id).set(IntegralSpuDomain::getIsEnabled,status));
    }

    @Override
    public Boolean updateById(Long id,IntegralSpuDomain integralSpuDomain) {
        return super.update(integralSpuDomain,Wrappers.<IntegralSpuDomain>lambdaQuery().eq(IntegralSpuDomain::getId,id));
    }
}
